<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            height: 300px;
            width: 100%;
            background-color: black;
        }
        .bs{
            height: 300px;
            width: 100%;
            background-color: white;
        }
    </style>
</head>
<body>
    <div>
        <button>开关灯</button>
    </div>
</body>
</html>
<script>
    var btn=document.querySelector('button');
    var hz=document.querySelector("div");
    var flag=0;
    btn.onclick=function(){
        if(flag==0){
                 hz.className='bs';
                 flag=1;
        }else{
            hz.className='div';
            flag=1;
        }
    }
</script>